package authentication.token.server;

import authentication.token.Request;
import authentication.token.Response;
import authentication.token.SignUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 登录控制器
 *
 * @author yuqi<307530884@qq.com> <2017/3/28>
 * @version 1.0
 * @since 1.0
 */
public class LoginController {

    public static final String LOGIN_URL = "http://localhost:8080/ccuas/loginIn";

    public static final String GET_LIST_URL = "http://localhost:8080/ccuas/getList";

    private transient final Logger logger = LoggerFactory.getLogger(getClass());

    public void loginIn(Request request, Response response){
        logger.info("loginIn request:{}", request);
        try {
            //验证签名
            String aseKey = SignUtil.checkLoginSignAndGetKey(request);

            //验证用户名密码

            //生成token
            String token = SignUtil.createLoginSuccessToken(aseKey);
            response.put("code", "1");
            response.put("msg", "success");
            response.put("token", token);
        } catch (Exception e) {
            e.printStackTrace();
            response.put("code", "-1");
            response.put("msg", "error");
        }
    }

}
